
package com.showcai.controller.dictation;

import com.showcai.controller.base.BaseController;
import com.showcai.module.Media;
import com.showcai.module.MediaClassify;
import com.showcai.result.ResultObj;
import com.showcai.service.MediaClassifyService;
import com.showcai.service.MediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lutao on 2017/7/14.
 */
@RequestMapping("/dictation")
@Controller
public class DictationController extends BaseController {
    @Autowired
    MediaService mediaService;
    @Autowired
    MediaClassifyService mediaClassifyService;

    /**
     * 获取听写列表
     *
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.POST)
    @ResponseBody
    public String index() {
        ResultObj resultObj = new ResultObj();
        Map<String,String> map = new HashMap<>();
        map.put("parentId",String.valueOf(8l));
        List<MediaClassify> mediaClassifylist = mediaClassifyService.getMediaClassify(map);
        logger.info(mediaClassifylist);
        resultObj.setData(mediaClassifylist);
        resultObj.setMsg("操作成功！");
        return resultObj.toJson();
    }
    /**
     * 获取年级列表
     *
     * @return
     */
    @RequestMapping(value = "/mediaClassifyList", method = RequestMethod.POST)
    @ResponseBody
    public String mediaClassifyList(Long tid,String devicId) {
        ResultObj resultObj = new ResultObj();
        Map<String,String> map = new HashMap<>();
        map.put("parentId",String.valueOf(tid));
        List<MediaClassify> mediaClassifylist = mediaClassifyService.getMediaClassify(map);
        for (MediaClassify mediaClassify:mediaClassifylist){
            map.put("classify",String.valueOf(mediaClassify.getTid()));
            map.put("devicId",devicId);
            List<Media> medialist = mediaService.selectMediaList(map);
            mediaClassify.setMediaList(medialist);
        }
        logger.info(mediaClassifylist);
        resultObj.setData(mediaClassifylist);
        resultObj.setMsg("操作成功！");
        return resultObj.toJson();
    }



}
